package com.lagou.order.dao;

import com.lagou.order.pojo.Good;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author stevejson
 */
public interface GoodDao extends JpaRepository<Good, Integer> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update t_good set `count` = `count` + 1 where id = :id")
    Integer incrCount(@Param("id")Integer id);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update t_good set `count` = `count` - 1 where id = :id")
    Integer decrCount(@Param("id")Integer id);

}
